package com.sci99.ex.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import com.sci99.ex.model.Exam;
import com.sci99.ex.util.MyBatisUtil;

public class ExamService {
	Logger log = Logger.getLogger(ExamService.class);

	public static List<Exam> getExams(Long cid) throws Exception {
		SqlSession s = MyBatisUtil.getSession();
		Map<String, Object> args = new HashMap<>();
		args.put("courseId", cid);
		List<Exam> l = s.selectList("getExam", args);
		s.close();
		return l;
	}

	public static void saveExam(Exam e) throws Exception {
		SqlSession s = MyBatisUtil.getSession();
		if (e.getId() == null)
			s.insert("addExam", e);
		else
			s.update("uptExam", e);
		s.commit();
		s.close();
	}

	public static void delExam(Exam e) throws Exception {
		SqlSession s = MyBatisUtil.getSession();
		s.delete("delExam", e);
		s.commit();
		s.close();
	}
}
